home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F45186_xsBuildXPath.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2001-07-19  |  4.4 KB  |  101 lines

  1. <xsl:stylesheet version='1.0'
  2. xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
  3. xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  4. >
  5.  
  6. <xsl:output method="text"/>
  7. <xsl:variable name="theParmNodes" select="//namespace::*[local-name() =
  8. 'myNamespace']"/>
  9. <xsl:template match="/">
  10.   <xsl:variable name="theResult">
  11.     <xsl:for-each select="$theParmNodes">
  12.     <xsl:variable name="theNode" select="."/>
  13.     <xsl:for-each select="$theNode |
  14. $theNode/ancestor-or-self::node()[..]">
  15.       <xsl:element name="slash">/</xsl:element>
  16.       <xsl:choose>
  17.         <xsl:when test="self::*">
  18.           <xsl:element name="nodeName">
  19.             <xsl:value-of select="name()"/>
  20.             <xsl:variable name="thisPosition"
  21.                 select="count(preceding-sibling::*[name(current()) =
  22.                         name()])"/>
  23.             <xsl:variable name="numFollowing"
  24.                 select="count(following-sibling::*[name(current()) =
  25.                         name()])"/>
  26.             <xsl:if test="$thisPosition + $numFollowing > 0">
  27.               <xsl:value-of select="concat('[', $thisPosition +
  28.                                                            1, ']')"/>
  29.             </xsl:if>
  30.           </xsl:element>
  31.         </xsl:when>
  32.         <xsl:otherwise> <!-- This node is not an element -->
  33.           <xsl:choose>
  34.             <xsl:when test="count(. | ../@*) = count(../@*)">
  35.             <!-- Attribute -->
  36.               <xsl:element name="nodeName">
  37.                 <xsl:value-of select="concat('@',name())"/>
  38.               </xsl:element>
  39.             </xsl:when>
  40.             <xsl:when test="self::text()">    <!-- Text -->
  41.               <xsl:element name="nodeName">
  42.                 <xsl:value-of select="'text()'"/>
  43.                 <xsl:variable name="thisPosition"
  44.                           select="count(preceding-sibling::text())"/>
  45.                 <xsl:variable name="numFollowing"
  46.                           select="count(following-sibling::text())"/>
  47.                 <xsl:if test="$thisPosition + $numFollowing > 0">
  48.                   <xsl:value-of select="concat('[', $thisPosition +
  49.                                                            1, ']')"/>
  50.                 </xsl:if>
  51.               </xsl:element>
  52.             </xsl:when>
  53.             <xsl:when test="self::processing-instruction()">
  54.             <!-- Processing Instruction -->
  55.               <xsl:element name="nodeName">
  56.                 <xsl:value-of select="'processing-instruction()'"/>
  57.                 <xsl:variable name="thisPosition"
  58.                    select="count(preceding-sibling::processing-instruction())"/>
  59.                 <xsl:variable name="numFollowing"
  60.                     select="count(following-sibling::processing-instruction())"/>
  61.                 <xsl:if test="$thisPosition + $numFollowing > 0">
  62.                   <xsl:value-of select="concat('[', $thisPosition +
  63.                                                             1, ']')"/>
  64.                 </xsl:if>
  65.               </xsl:element>
  66.             </xsl:when>
  67.             <xsl:when test="self::comment()">    <!-- Comment -->
  68.               <xsl:element name="nodeName">
  69.                 <xsl:value-of select="'comment()'"/>
  70.                 <xsl:variable name="thisPosition"
  71.                          select="count(preceding-sibling::comment())"/>
  72.                 <xsl:variable name="numFollowing"
  73.                          select="count(following-sibling::comment())"/>
  74.                 <xsl:if test="$thisPosition + $numFollowing > 0">
  75.                   <xsl:value-of select="concat('[', $thisPosition +
  76.                                                             1, ']')"/>
  77.                 </xsl:if>
  78.               </xsl:element>
  79.             </xsl:when>
  80.             <!-- Namespace: -->
  81.             <xsl:when test="count(. | ../namespace::*) =
  82.                                                count(../namespace::*)">
  83.  
  84.               <xsl:variable name="apos">'</xsl:variable>
  85.               <xsl:element name="nodeName">
  86.                 <xsl:value-of select="concat('namespace::*',
  87.                 '[local-name() = ', $apos, local-name(), $apos, ']')"/>
  88.  
  89.               </xsl:element>
  90.             </xsl:when>
  91.           </xsl:choose>
  92.         </xsl:otherwise>
  93.       </xsl:choose>
  94.     </xsl:for-each>
  95.     <xsl:text> </xsl:text>
  96.   </xsl:for-each>
  97.  </xsl:variable>
  98.  <xsl:value-of select="msxsl:node-set($theResult)"/>
  99. </xsl:template>
  100. </xsl:stylesheet>
  101.